package com.yumeng.system.main.auth;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yumeng.common.auth.BaseAuthInfo;
import com.yumeng.framework.auth.service.auth.SmsAuthService;
import com.yumeng.common.data.enums.AuthMode;
import com.yumeng.common.data.enums.DelFlag;
import com.yumeng.system.main.entity.SysUser;
import org.springframework.stereotype.Service;

/**
 * 手机短信认证实现
 *
 * @author wxd
 * @date 2025/4/10 10:29
 */
@Service(SmsAuthServiceImpl.DEFAULT_BEAN_NAME)
public class SmsAuthServiceImpl  extends BaseAuthServiceImpl implements SmsAuthService {

    public static final String DEFAULT_BEAN_NAME = "smsAuthServiceImpl";

    @Override
    protected BaseAuthInfo doFindByAuthKey(String authKey) {
        LambdaQueryWrapper<SysUser> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysUser::getPhone, authKey).eq(SysUser::getDelFlag, DelFlag.UN_DEL);
        SysUser sysUser = sysUserDao.mapper().selectOne(wrapper);
        if (sysUser == null) {
            return null;
        }
        return createAuthInfo(sysUser, AuthMode.SMS);
    }
}
